﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace WeiXinPF.Modules.Core.Admin.Application.Services
{
    public class ADService : IADService
    {
        public IEnumerable<Model.advertisement> GetAdvertismentsByCategoryId(
            int weixinId, int userId, int categoryId)
        {
            StringBuilder conditionBuilder = new StringBuilder();
            conditionBuilder.Append("isdelete=0");
            conditionBuilder.AppendFormat(" and wid={0}", weixinId);
            conditionBuilder.AppendFormat(" and categoryid={0}", categoryId);

            BLL.advertisement bll = new BLL.advertisement();
            DataSet artDs = bll.GetList(Int32.MaxValue, conditionBuilder.ToString(),false);
            if (artDs == null || artDs.Tables.Count == 0)
            {
                return new List<Model.advertisement>();
            }
            
            return new AdvertisementParser().ParseAdvertisements(artDs.Tables[0].Select());
        }

        public void Add(Model.advertisement model)
        {

        }

        public void Update(Model.advertisement model)
        {

        }

        public void delete(int id)
        {

        }

        public string GetCateGoryNamebyID(int categoryid)
        {
            return new BLL.advertisement().GetCateGoryNamebyID(categoryid);
        }

        public int GetCateGoryIDbyName(string categoryname)
        {
            return new BLL.advertisement().GetCateGoryIDbyName(categoryname);
        }

        public DataTable GetAllCateGory()
        {
            return new BLL.advertisement().GetAllCateGory();
        }
    }
}
